#!/usr/bin/env perl
#################################################################################
#
# The confidential and proprietary information contained in this file may
# only be used by a person authorised under and to the extent permitted
# by a subsisting licensing agreement from Jeejio Limited.
#
#                 (C) COPYRIGHT 2018-2019 JEEJIO Limited.
#                       ALL RIGHTS RESERVED
#
# This entire notice must be reproduced on all copies of this file
# and copies of this file may only be made by a person if such person is
# permitted to do so under the terms of a subsisting license agreement
# from JEEJIO Limited.
#
#	       utarback
#	       ============
#
#
################################################################################

if ($#ARGV != 0) {
  print "\nUsage Format:  utarback xxx \n\n";
  print "\nAttention   :  You must come to the path \n\n";
  print "\n               which have many t0000,t0001,t0002,... files \n\n";
  die();
}

#-----delete the first input character when it including the "/" or "." and so on.
$_=$ARGV[0];
s/\W+\s*$//g; ## delete the "/" when the character including the "/" or "." and so o
$inFileName = $_;
$binName=$inFileName."bin";
$mainFoler="tt".$inFileName;

#----------------------------------------------------------
#Test the file exist or not. 
#die "file $inFileName is not exist! \n" unless -e $inFileName;

################################################################################
# content begin
################################################################################

#Step1 gather many files to one file,  
system("cat * > $inFileName");
#Step2 delete line 13 to 17 for unsecuriy ,for the reason see tarback  
##system("sed -i '13,17d' $inFileName");
#Step3 hex file to bin file, hex2bin auto generate binName
system("hex2bin $inFileName ");
#Step4 untar file to org file or folders 
if( -e $mainFoler){
  system("rm -rf $mainFoler");
}
system("mkdir $mainFoler");
system("mv $inFileName $mainFoler");
system("mv $binName $mainFoler");
system("tar -zxpf $mainFoler/$binName");

################################################################################
# content end 
################################################################################
#
print "utarback successfully!\n";

